<template>
  <div>
    <div class="historyhotbox" v-show="histoyIsShow">
      <div class="history_header">
        <p>历史记录</p>
        <van-icon name="delete-o" @click="clearhistoy" />
      </div>
      <div class="history_tag">
        <van-tag
          :text-color="item.is_hot == 1 ? 'red' : '#666'"
          plain
          type="primary"
          v-for="(item, index) in historyKeywordList"
          :key="index"
          @click="tagChange(item)"
          >{{ item }}</van-tag
        >
      </div>
    </div>

    <div class="historyhotbox">
      <div class="history_header">
        <p>热门搜索</p>
        <!-- <van-icon name="delete-o"/> -->
      </div>
      <div class="history_tag">
        <van-tag
          plain
          type="primary"
          :text-color="item.is_hot == 1 ? 'red' : '#666'"
          v-for="(item, index) in hotKeywordList"
          :key="index"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import { clearHihistoryApi } from "../../request/api";
export default {
  data() {
    return {
      //历史记录显示隐藏的状态
      histoyIsShow: true,
    };
  },
  props: ["historyKeywordList", "hotKeywordList"],
  methods: {
    tagChange(value) {
      console.log(value);
      this.$emit("tagChange", value);
    },
    clearhistoy() {
      // 清除历史记录
      clearHihistoryApi().then((res) => {
        if (res.data.errno == 0) {
          setTimeout(() => {
            this.histoyIsShow = false;
            this.$toast.success("删除成功 ");
          }, 300);
        }
      });
    },
  },
};
</script>
 
<style lang = "less" scoped>
.historyhotbox {
  background-color: white;
  margin-bottom: 0.2rem;
  padding: 0.1rem;
  .history_header {
    padding-bottom: 0.1rem;
    p {
      font-size: 0.18rem;
    }
    display: flex;
    justify-content: space-between;
  }
  .history_tag {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: start;

    .van-tag {
      margin-right: 0.1rem;
      margin-bottom: 0.1rem;
    }
  }
}
</style>